<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Validate;

class Reg extends Controller
{
    
    public function reg()
    {
        $data['username'] = "admin1";
        $data['pass'] =123456;
        $data['addtime']=time();
        $rule = [
            'username' => 'require|max:25|unique:admin_user',
            'pass' => 'require|number|between:3,200000',
            ];
        $msg = [
            'username.require' => '名称必须',
            'username.max' => '名称最多不能超过25个字符',
            'pass.number' => '密码必须是数字',
            'pass.between' => '密码只能在3,20之间',
            'pass.require' => '密码必须',
            'username.unique:admin_user' => '名称唯一',
            ];
        $validate = new Validate($rule, $msg);
        $result = $validate->check($data);
        if ($result!==true) {
            return $validate->getError();
        }
        $data['pass'] =md5(123456);
        Db::name('admin_user')->insert($data);
        // var_dump($data);
      
        
        
    }

   
}
